package crivia.db.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;

import crivia.db.a.DataSet_AC;

public class DataSet_jdbc_Column extends DataSet_AC {
	
	public DataSet_jdbc_Column(Connection connection , PreparedStatement cmd , ResultSet rs){
		this(rs);
		try {
			cmd.close();
			connection.close();
		} catch (SQLException e) {
			throw new crivia.db.exception.SQLMiss(e);
		}
	}
	
	public DataSet_jdbc_Column(ResultSet rs){
		try {
			ResultSetMetaData metaData = rs.getMetaData();
			for (int k = 0; k < metaData.getColumnCount(); k++){
				String key = metaData.getColumnName(k+1);
				rawKeys.add(key);
				datas.put(key.toLowerCase(), new ArrayList<String>());
			}
			while (rs.next()){
				for (int k = 0; k < metaData.getColumnCount(); k++){
					String c = metaData.getColumnName(k+1);
					addValue(c, rs.getString(c));
				}
			}
			rs.close();
		} catch (SQLException e) {
			throw new crivia.db.exception.SQLMiss(e);
		}
	}

}
